package com.lagou.controller;

import com.lagou.controller.service.EmailServiceFeignClient;
import com.lagou.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/code")
public class CodeController {

    @Autowired
    EmailServiceFeignClient eamilFeignClient;
    @Autowired
    CodeService codeService;

    @GetMapping("/create/{email}")
    public boolean findDefaultResumeState(@PathVariable String email) {
        String code = codeService.createCode(email);
        boolean succ = eamilFeignClient.sendCodeEmail(email, code);
        return true;
    }

    @GetMapping("/validate/{email}/{code}")
    public int validate(@PathVariable String email, @PathVariable String code) {
        return codeService.checkCode(email, code);
    }

}
